﻿using Client;
using Shared.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ManageSystem.Dialog
{
    public partial class DialogProvince : Form
    {
        private TextBox _retText = null;
        private PROVINCE _provinceW = null;

        public DialogProvince(TextBox text, PROVINCE provinceW=null)
        {
            if (text == null)//没有传入NODE时关闭窗口
            {
                MessageBox.Show("传入参数为空");
                Close();
            }

            _retText = text;
            _provinceW = provinceW;
            InitializeComponent();
        }

        //设置listview
        private void SetListView(ListView view, PROVINCE prov)
        {
            if (view == null || prov == null) return;
            ListViewItem item = new ListViewItem();
            item.Text = prov.PROVINCE_CODE;

            item.SubItems.Add(prov.PROVINCE_NAME);


            view.Items.Add(item);
        }
        //清空list view
        private void ClearListView(ListView view)
        {
            view.Items.Clear();
        }

        private void DialogProvince_Load(object sender, EventArgs e)
        {
            if (_provinceW == null) _provinceW = new PROVINCE();
            var selectProv = MethodWcf.SelectProvinceClient(_provinceW);
            if (selectProv.result)
            {
                for (int i = 0; i < selectProv.value.Count; i++)
                {
                    SetListView(this.listViewProvince, selectProv.value[i]);
                }
            }
            else//未能获得信息则关闭这个界面
            {
                MessageBox.Show(selectProv.message);
                this.Close();
            }
        }

        private void listViewProvince_MouseClick(object sender, MouseEventArgs e)
        {
            var choiceCode = this.listViewProvince.SelectedItems[0].Text;//选择的ID

            _retText.Text = choiceCode;

            this.Close();
        }
    }
}
